<template>
  <div id="list" >
    <el-row type="flex" align="middle" style="text-align: center; background-color: #ffffff">
      <!-- <el-image
        :src="require('../../assets/vsmlogo.png')"
        fit="fit"
        style="height: 50px"
      ></el-image> -->
      <el-input placeholder="请输入内容" v-model="input" class="searchClass" style="height: 50px">
        <el-button slot="append" icon="el-icon-search" @click="jump" type='submit'></el-button>
      </el-input>
    </el-row>
    <el-row style="margin: 5px 0 5px 20px">
      根据检索内容：<span style="color: #EE6365">{{ searchInfo }} </span>,共<span style="color: #EE6365"> {{ blength
        }} </span>条检索结果
    </el-row>
    <el-divider></el-divider>
    <div :key="menuKey">
      <el-row v-for="(item, index) in bookResult.slice(
          (currentPage - 1) * pagesize,
          currentPage * pagesize
        )" :key="index" :class="juclass(index)">
        <el-row :gutter="20" style="margin: 0px 20px; padding: 10px 10px" type="flex" align="middle">
          <!-- <el-col :span="1" style="text-align: center">{{(currentPage-1)*pagesize+ index + 1 }}</el-col> -->
          <el-col :span="3" style="text-align: center">
            <el-row>
              <el-image :src="item.picture" fit="fit" style="height: 150px"></el-image>
            </el-row>
            <el-row><span style="font-size: 13px; color: #4e5050">{{
                item.publish
                }}</span></el-row>
          </el-col>
          <el-col :span="16">
            <el-row style="font-size: 18px; font-weight: bold" align="top">{{
              item.name
              }}</el-row>
            <el-row style="font-size: 10px; color: #5f5d5a; margin: 5px 0">{{
              item.author
              }}</el-row>
            <el-row style="font-size: 15px; color: rgb(25 25 24)">{{
              item.introduction
              }}</el-row>
          </el-col>
          <el-col :span="5" style="text-align: center">
            <el-button round @click="handle(item.detaillink)">查看</el-button>
          </el-col>
        </el-row>
        <!-- <el-row> <el-divider></el-divider></el-row> -->
      </el-row>
      <el-divider></el-divider>
      <el-pagination style="padding: 15px 0px 10px 30px;" @size-change="handleSizeChange"
        @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-sizes="[5, 10, 15, 20]"
        :page-size="pagesize" layout="total,sizes,prev,pager,next,jumper" :total="bookResult.length">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  import axios from "axios";
  export default {
    inject: ['reload'],
    data() {

      return {
        input: "",
        select: "",
        menuKey:1,
        searchInfo: "",
        currentPage: 1,
        pagesize: 5,
        blength: 0,
        totalCount: 1,
        listnumber: 78,
        bookResult: [],
      };
    },
    components: {},
    // mounted() {
    //   this.getinfo();
    // },
    created() {
      // 如果是跳转来的，则接受初始化参数
      if (this.$route.query) {
        this.bookResult = this.$route.query.searchData;
        this.searchInfo = this.$route.query.searchInfo;
        this.blength = this.bookResult.length;
      }
    },
    methods: {
      getinfo() {
        const self = this;
        self.bookResult = this.$router.params.searchData;
        self.searchInfo = this.$router.params.searchInfo;
        console.log("bookResult:", self.bookResult);
        console.log("searchInfo:", self.searchInfo);
      },
      juclass(index) {
        if (index % 2 === 0) {
          return "type1";
        } else {
          return "type2";
        }
      },
      jump() {
        var that = this;
        if (!that.input) {
          that.$message.warning("请输入搜索内容!");
          return false;
        } else {
          axios
            .get("http://127.0.0.1:5000/getMsg?searchinfo=" + that.input)
            .then((response) => {
              // alert(response.data[0]);
              // that.searchData = response.data;
        
              console.log("response.data:", response.data);
              ++this.menuKey
              that.bookResult = response.data;
              that.searchInfo = that.input;
              that.blength = that.bookResult.length;
             
              // this.$router.push({
              //   path: "/list",
              //   query: { searchData: response.data, searchInfo: that.input },
              // });
            });
        }
      },
      // rebuild() {
      //   window.location.reload()
      // },

      handle(url) {
        window.open(url, "_blank");
      },
      handleSizeChange(val) {
        this.pagesize = val;
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.currentPage = val;
      },
      totalPageNum() {
        const self = this;
        self.totalCount = self.bookResult.length;
        // this.$axios
        //   .get("/api/pagePackMade.do")
        //   .then((res) => {
        //     this.totalCount = res.data[0].count;
        //   })
        //   .catch((error) => {
        //     console.log(error);
        //   });
      },
    },
    // watch: {
    //   '$route': 'reload'
    // }
  };
</script>
<style>
  /* #list{
  background-color: #d6e1eb;
} */
  body {
    background-color: #dadde270;
  }

  .type1 {
    background-color: #b1bdc5a6;
  }

  .type2 {
    background-color: #dadde270;
  }

  .searchClass {
    width: 60%;
    border: 1px solid #c5c5c5;
    border-radius: 20px;
    background: #f7fafb;
    margin: 20px auto;
  }

  .el-divider--horizontal {
    display: block;
    height: 1px;
    width: 100%;
    margin: 0;
  }

  .searchClass .el-input-group__prepend {
    border: none;
    background-color: transparent;
    padding: 0 10px 0 30px;
  }

  .searchClass .el-input-group__append {
    border: none;
    background-color: transparent;
  }

  .searchClass .el-input__inner {
    height: 50px;
    line-height: 50px;
    border: none;
    background-color: transparent;
  }

  .searchClass .el-icon-search {
    font-size: 16px;
  }

  .searchClass .centerClass {
    height: 100%;
    line-height: 100%;
    display: inline-block;
    vertical-align: middle;
    text-align: right;
  }

  .searchClass .line {
    width: 1px;
    height: 26px;
    background-color: #eaf0f1;
    margin-left: 14px;
  }

  .searchClass:hover {
    border: 1px solid #d5e3e8;
    background: #fff;
  }

  .searchClass:hover .line {
    background-color: #d5e3e8;
  }

  .searchClass:hover .el-icon-search {
    color: #409eff;
    font-size: 16px;
  }
</style>